var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        page: 1,
        listRows: 10,
        total: 0
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
    },
    getData: function() {
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            page: _this.params.page,
            listRows: _this.params.listRows,

        };
        console.log(paramsObj);
        Api.getactivitymessagelist(paramsObj, function(data) {
            console.log(data);
            _this.getDataList(data.messageList);
            _this.params.total = data.totalPages;
            layui.use('laypage', function() {
                var laypage = layui.laypage;
                //执行一个laypage实例
                laypage.render({
                    elem: 'page',
                    index: 1,
                    theme: '#3498db',
                    curr: _this.params.page,
                    count: _this.params.total, //数据总数，从服务端得到
                    hash: 'curr_page',
                    layout: ['prev', 'page', 'next', 'skip'],
                    jump: function(obj, first) {
                        _this.params.page = obj.curr;
                        //obj包含了当前分页的所有参数，比如：curr当前页
                        var Params = {
                            passport: _this.params.passport,
                            page: _this.params.page,
                            listRows: _this.params.listRows,

                        };
                        Api.getactivitymessagelist(Params, function(data) {
                            _this.getDataList(data.messageList);

                        })
                    }
                });
            });
        });
    },
    getDataList: function(data) {
        var _this = this;
        if (data && data.length > 0) {
            var html = '',
                i = 0,
                len = data.length;
            for (i; i < len; i++) {
                html += '<tr>'+
                            // '<td>'+
                            //     '<div class="goods-checkbox">'+
                            //         '<div class="check-box">'+
                            //             '<input type="checkbox" messageId="'+data[i].messageId+'">'+
                            //         '</div>'+
                            //     '</div>'+
                            // '</td>'+
                            '<td class="text-c">'+data[i].messageId+'</td>'+
                            '<td class="text-c">'+data[i].title+'</td>'+
                            '<td class="text-c">'+data[i].releaseTime+'</td>'+
                            '<td class="text-c">'+data[i].adminName+'</td>';
                    if (data[i].pushType=='text') {
                        html+='<td class="text-c">文字</td>';
                    }else{
                        html+='<td class="text-c">链接</td>';
                    };
                    if (data[i].releaseStatus==0) {
                        html+='<td class="text-c">否</td>';
                    }else{
                        html+='<td class="text-c">是</td>';
                    };
                    if (data[i].isPush==0) {
                        html+='<td class="text-c">否</td>';
                    }else{
                        html+='<td class="text-c">是</td>';
                    };

                        html+='<td class="text-c">'+data[i].pushTime+'</td>'+
                            // '<td class="text-c">'+data[i].client+'</td>'+
                            '<td class="text-c">'+
                                '<a class="handle view" messageId="'+data[i].messageId+'">查看详情</a>'+
                            '</td>'+
                        '</tr>';
            }
            $('#List').html(html);
            $('tfoot').css('display', 'table-footer-group');
            _this.getDataEvent();
        } else {
            var html = '<tr>' +
                '<td class="text-c c-666" colspan="9" >暂无数据</td>' +
                '</tr>';
            $('#List').html(html);
            $('tfoot').css('display', 'none');
        }
    },
    getDataEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('.view').on('click', function() {
            Pub.setSession('messageId', $(this).attr('messageId'));
            window.location.href = Pub.getHtmlUrl('./activity-list-detail.html');
        });
        $('input[type=checkbox][name=all]').on('ifChanged', function() {
            if ($(this).is(':checked')) {
                $('input[type=checkbox][name=new]').iCheck('check');
            } else {
                $('input[type=checkbox][name=new]').iCheck('uncheck');
            }
        });
    },
    otherEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
    },
    initEvent: function(){
        var _this = this;
         _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();